<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">












<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=6.3.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=6.3.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=6.3.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=6.3.0">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=6.3.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '6.3.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="记录这个博客搭建过程，目前为止用到的功能如下，不断丰富中  hexo生成代码 next主题 码云web服务 leancloud记录阅读量  编译并提交 123456e:cd E:\blog\public\bloghexo ggit add .git commit -am &apos;备注&apos;git push">
<meta name="keywords" content="hexo">
<meta property="og:type" content="article">
<meta property="og:title" content="hexo搭建个人博客">
<meta property="og:url" content="http://yoursite.com/code/hexo/develop/hexo搭建blog/index.html">
<meta property="og:site_name" content="我的云笔记">
<meta property="og:description" content="记录这个博客搭建过程，目前为止用到的功能如下，不断丰富中  hexo生成代码 next主题 码云web服务 leancloud记录阅读量  编译并提交 123456e:cd E:\blog\public\bloghexo ggit add .git commit -am &apos;备注&apos;git push">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://yoursite.com/blog/images/1532892250057.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532877733213.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532877925010.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532878027383.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532880622334.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532880847798.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532882626864.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532883398241.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532883459275.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532883485461.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532884043812.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532883923533.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532893106342.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532885753389.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532885611516.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532687467766.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532931914832.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532932008703.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532932150226.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532932378669.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532932631263.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532933159586.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532896295850.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532933462735.png">
<meta property="og:image" content="http://yoursite.com/blog/images/1532949407329.png">
<meta property="og:updated_time" content="2019-10-05T05:57:31.677Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="hexo搭建个人博客">
<meta name="twitter:description" content="记录这个博客搭建过程，目前为止用到的功能如下，不断丰富中  hexo生成代码 next主题 码云web服务 leancloud记录阅读量  编译并提交 123456e:cd E:\blog\public\bloghexo ggit add .git commit -am &apos;备注&apos;git push">
<meta name="twitter:image" content="http://yoursite.com/blog/images/1532892250057.png">






  <link rel="canonical" href="http://yoursite.com/code/hexo/develop/hexo搭建blog/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>hexo搭建个人博客 | 我的云笔记</title>
  






  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?5102824f4157d2cbdb282a1a889d910e";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">我的云笔记</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/blog/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">
    <a href="/blog/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">
    <a href="/blog/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/code/hexo/develop/hexo搭建blog/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的云笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">hexo搭建个人博客
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-07-29 17:27:11" itemprop="dateCreated datePublished" datetime="2018-07-29T17:27:11+08:00">2018-07-29</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-10-05 13:57:31" itemprop="dateModified" datetime="2019-10-05T13:57:31+08:00">2019-10-05</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/code/" itemprop="url" rel="index"><span itemprop="name">code</span></a></span>

                
                
                  ，
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/code/hexo/" itemprop="url" rel="index"><span itemprop="name">hexo</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/blog/code/hexo/develop/hexo搭建blog/" class="leancloud_visitors" data-flag-title="hexo搭建个人博客">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>记录这个博客搭建过程，目前为止用到的功能如下，不断丰富中</p>
<ol>
<li><a href="https://hexo.io/zh-cn/" target="_blank" rel="noopener">hexo</a>生成代码</li>
<li><a href="http://theme-next.iissnan.com/" target="_blank" rel="noopener">next</a>主题</li>
<li><a href="https://gitee.com/" target="_blank" rel="noopener">码云</a>web服务</li>
<li><a href="https://leancloud.cn/" target="_blank" rel="noopener">leancloud</a>记录阅读量</li>
</ol>
<p>编译并提交</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">e:</span><br><span class="line">cd E:\blog\public\blog</span><br><span class="line">hexo g</span><br><span class="line">git add .</span><br><span class="line">git commit -am '备注'</span><br><span class="line">git push</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<h1 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h1><p>这些工作因为以前就做过了，这里就不专门写出来了，</p>
<ol>
<li>安装npm（Node Package Manager ），我的版本是5.6.0</li>
<li>安装TortoiseGit，我的版本是TortoiseGit 2.6.0.0</li>
<li>注册码云账号，并创建项目，这里定的项目名称是blog</li>
<li>本地新建目录，我用的是：E:\blog，下面如果没特殊说明，所有命令均是在这个目录下执行的</li>
</ol>
<p>下面正式开始</p>
<p>进入工作目录</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">E:</span><br><span class="line">cd blog</span><br></pre></td></tr></table></figure>
<p><img src="/blog/images/1532892250057.png" alt="1532892250057"></p>
<h1 id="安装hexo"><a href="#安装hexo" class="headerlink" title="安装hexo"></a>安装hexo</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -g hexo</span><br></pre></td></tr></table></figure>
<h1 id="创建项目"><a href="#创建项目" class="headerlink" title="创建项目"></a>创建项目</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo init</span><br></pre></td></tr></table></figure>
<p><img src="/blog/images/1532877733213.png" alt="1532877733213"></p>
<p>启动，如果不行就执行一下npm install</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo s</span><br></pre></td></tr></table></figure>
<p><img src="/blog/images/1532877925010.png" alt="1532877925010"></p>
<p>打开浏览器,在地址栏输入输入：<a href="http://127.0.0.1:4000/" target="_blank" rel="noopener">http://127.0.0.1:4000/</a> 就可以直接访问了</p>
<p><img src="/blog/images/1532878027383.png" alt="1532878027383"></p>
<h1 id="更换主题"><a href="#更换主题" class="headerlink" title="更换主题"></a>更换主题</h1><p>个人选的是<a href="https://github.com/theme-next/hexo-theme-next" target="_blank" rel="noopener">NexT</a></p>
<p>可以到网站上将其下载到主题目录E:\blog\themes，也可以直接用git命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone https://github.com/theme-next/hexo-theme-next.git themes/next</span><br></pre></td></tr></table></figure>
<p>修改项目根路径下的配置文件（e:/blog/_config.yml，后面简称站点文件）</p>
<p>将theme改为next</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Extensions</span></span><br><span class="line"><span class="comment">## Plugins: https://hexo.io/plugins/</span></span><br><span class="line"><span class="comment">## Themes: https://hexo.io/themes/</span></span><br><span class="line"><span class="attr">theme:</span> <span class="string">next</span></span><br></pre></td></tr></table></figure>
<p>修改next的配置文件（E:/blog/themes/next/_config.yml，后面简称主题文件）</p>
<p>还可以进一步更换样式,目前可选的有下面这些，根据个人喜好，可自行选择</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Schemes</span></span><br><span class="line"><span class="comment">#scheme: Muse</span></span><br><span class="line"><span class="comment">#scheme: Mist</span></span><br><span class="line"><span class="attr">scheme:</span> <span class="string">Pisces</span></span><br><span class="line"><span class="comment">#scheme: Gemini</span></span><br></pre></td></tr></table></figure>
<h1 id="基础配置"><a href="#基础配置" class="headerlink" title="基础配置"></a>基础配置</h1><h2 id="标题"><a href="#标题" class="headerlink" title="标题"></a>标题</h2><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">title:</span> <span class="string">个人博客</span></span><br></pre></td></tr></table></figure>
<h2 id="语言"><a href="#语言" class="headerlink" title="语言"></a>语言</h2><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">language:</span> <span class="string">zh-CN</span></span><br></pre></td></tr></table></figure>
<p>语言是和这个目录下的文件对应的：E:\blog\themes\next\languages</p>
<p><img src="/blog/images/1532880622334.png" alt="1532880622334"></p>
<h2 id="添加分类和标签"><a href="#添加分类和标签" class="headerlink" title="添加分类和标签"></a>添加分类和标签</h2><h3 id="新建页面"><a href="#新建页面" class="headerlink" title="新建页面"></a>新建页面</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">hexo new page categories</span><br><span class="line">hexo new page tage</span><br></pre></td></tr></table></figure>
<p><img src="/blog/images/1532880847798.png" alt="1532880847798"></p>
<h3 id="修改生成页面的内容"><a href="#修改生成页面的内容" class="headerlink" title="修改生成页面的内容"></a>修改生成页面的内容</h3><p>E:\blog\source\categories\index.md</p>
<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: 分类</span><br><span class="line">date: 2018-07-30 00:12:56</span><br><span class="line">type: "categories"</span><br><span class="line">---</span><br></pre></td></tr></table></figure>
<p>E:\blog\source\tags\index.md</p>
<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: 标签</span><br><span class="line">date: 2018-07-30 00:13:55</span><br><span class="line">type: "tags"</span><br><span class="line">---</span><br></pre></td></tr></table></figure>
<h3 id="修改主题文件"><a href="#修改主题文件" class="headerlink" title="修改主题文件"></a>修改主题文件</h3><p>根据需要选择要显示的页面，因为分类和标签对个人比较有用，就先开放这两个</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">menu:</span></span><br><span class="line"><span class="attr">  home:</span> <span class="string">/</span> <span class="string">||</span> <span class="string">home</span></span><br><span class="line">  <span class="comment">#about: /about/ || user</span></span><br><span class="line"><span class="attr">  tags:</span> <span class="string">/tags/</span> <span class="string">||</span> <span class="string">tags</span></span><br><span class="line"><span class="attr">  categories:</span> <span class="string">/categories/</span> <span class="string">||</span> <span class="string">th</span></span><br><span class="line">  <span class="comment">#archives: /archives/ || archive</span></span><br><span class="line">  <span class="comment">#schedule: /schedule/ || calendar</span></span><br><span class="line">  <span class="comment">#sitemap: /sitemap.xml || sitemap</span></span><br><span class="line">  <span class="comment">#commonweal: /404/ || heartbeat</span></span><br></pre></td></tr></table></figure>
<h1 id="开始撰写"><a href="#开始撰写" class="headerlink" title="开始撰写"></a>开始撰写</h1><p>写博客唯一要做的事就是在这个目录（E:\blog\source_posts）下新建md文件</p>
<p>除了头部有一些特殊要求外，其余部分基本可以自由发挥</p>
<h2 id="头部信息"><a href="#头部信息" class="headerlink" title="头部信息"></a>头部信息</h2><p>文章标题和分类等信息需要按专门的格式写</p>
<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: 文章标题</span><br><span class="line">date: 2018-07-29 22:48:10</span><br><span class="line">categories: [一级分类,二级分类]</span><br><span class="line">tags: [标签1,标签2]</span><br><span class="line">---</span><br></pre></td></tr></table></figure>
<h2 id="文章主体"><a href="#文章主体" class="headerlink" title="文章主体"></a>文章主体</h2><p>通过more便签可以将文正分为简介和正文两部分，下面是一个简单示例</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">这里是内容简介，点击阅读全文可以看到更多内容</span><br><span class="line">&lt;!--more--&gt;</span><br><span class="line"><span class="meta">#</span> 这里是一级标题</span><br><span class="line"><span class="meta">#</span># 测试画图</span><br><span class="line">'``flow</span><br><span class="line">st=&gt;start: 开始</span><br><span class="line">op=&gt;operation: 操作</span><br><span class="line">cond=&gt;condition: 判断</span><br><span class="line">en=&gt;end: 结束</span><br><span class="line"><span class="meta">st-&gt;</span>op</span><br><span class="line"><span class="meta">op-&gt;</span>cond</span><br><span class="line"><span class="meta">cond(yes)-&gt;</span>en</span><br><span class="line">'``</span><br><span class="line"><span class="meta">#</span># 测试二级标题</span><br><span class="line"><span class="meta">#</span> 一级标题2</span><br><span class="line"><span class="meta">#</span> 一级标题3</span><br></pre></td></tr></table></figure>
<h1 id="实际效果"><a href="#实际效果" class="headerlink" title="实际效果"></a>实际效果</h1><h2 id="首页"><a href="#首页" class="headerlink" title="首页"></a>首页</h2><p><img src="/blog/images/1532882626864.png" alt="1532882626864"></p>
<h2 id="阅读全文"><a href="#阅读全文" class="headerlink" title="阅读全文"></a>阅读全文</h2><p><img src="/blog/images/1532883398241.png" alt="1532883398241"></p>
<h2 id="分类"><a href="#分类" class="headerlink" title="分类"></a>分类</h2><p><img src="/blog/images/1532883459275.png" alt="1532883459275"></p>
<h2 id="标签"><a href="#标签" class="headerlink" title="标签"></a>标签</h2><p><img src="/blog/images/1532883485461.png" alt="1532883485461"></p>
<h1 id="发布到网上"><a href="#发布到网上" class="headerlink" title="发布到网上"></a>发布到网上</h1><p>由于网速问题原因，我暂时未将项目发布到<a href="https://github.com/" target="_blank" rel="noopener">github</a>，而是用了<a href="https://gitee.com/" target="_blank" rel="noopener">码云</a></p>
<p>码云上提供了一个免费的Gitee Pages服务，可以用于展示静态页面</p>
<p><img src="/blog/images/1532884043812.png" alt="1532884043812"></p>
<p>只要在项目里点击服务，然后点击Gitee Pages，再启动就可以了</p>
<p><img src="/blog/images/1532883923533.png" alt="1532883923533"></p>
<h2 id="修改项目根路径"><a href="#修改项目根路径" class="headerlink" title="修改项目根路径"></a>修改项目根路径</h2><p>项目取名叫blog，所以最终发布到网上的网址为<a href="https://xixhaha.gitee.io/blog/" target="_blank" rel="noopener">https://xixhaha.gitee.io/blog/</a></p>
<p>为了保证页面和和资源能正常访问，需要对路径做一些修改</p>
<h2 id="修改网站文件"><a href="#修改网站文件" class="headerlink" title="修改网站文件"></a>修改网站文件</h2><p>将root改为/blog</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">root:</span> <span class="string">/blog</span></span><br></pre></td></tr></table></figure>
<h2 id="下载项目到本地"><a href="#下载项目到本地" class="headerlink" title="下载项目到本地"></a>下载项目到本地</h2><p>我下载到了这个目录：E:/blog/public/blog</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone https://gitee.com/xixhaha/blog.git public/blog</span><br></pre></td></tr></table></figure>
<h2 id="修改生成目录"><a href="#修改生成目录" class="headerlink" title="修改生成目录"></a>修改生成目录</h2><p>因为这个目录E:/blog/public/blog将会是最终的发布目录，所以要将生成的静态页面都放这里</p>
<p>修改站点文件</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">public_dir:</span> <span class="string">public/blog</span></span><br></pre></td></tr></table></figure>
<h2 id="生成静态页面"><a href="#生成静态页面" class="headerlink" title="生成静态页面"></a>生成静态页面</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo g</span><br></pre></td></tr></table></figure>
<h2 id="提交到网站"><a href="#提交到网站" class="headerlink" title="提交到网站"></a>提交到网站</h2><p>用的是TortoiseGit ，所以只需要在blog目录按右键选择git commit就可以了</p>
<p><img src="/blog/images/1532893106342.png" alt="1532893106342"></p>
<h3 id="commit"><a href="#commit" class="headerlink" title="commit"></a>commit</h3><p>填写备注，随便写点什么，然后点击All和Commit</p>
<p><img src="/blog/images/1532885753389.png" alt="1532885534198"></p>
<h3 id="push"><a href="#push" class="headerlink" title="push"></a>push</h3><p>commit后会转到push界面，直接点push</p>
<p><img src="/blog/images/1532885611516.png" alt="1532885611516"></p>
<p>换成命令就是</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">e:</span><br><span class="line">cd E:\blog\public\blog</span><br><span class="line">hexo g</span><br><span class="line">git add .</span><br><span class="line">git commit -am '备注'</span><br><span class="line">git push</span><br></pre></td></tr></table></figure>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>基本上这样个人的博客就算搭建完毕了，以后要撰写博客只需要进行以下几个步骤</p>
<ol>
<li>在E:\blog\blog_posts目录下新建md文件</li>
<li>开始撰写文章</li>
<li>执行命令 hexo g</li>
<li>git commit and git push</li>
</ol>
<h1 id="个性化配置"><a href="#个性化配置" class="headerlink" title="个性化配置"></a>个性化配置</h1><h2 id="按分类生成路径"><a href="#按分类生成路径" class="headerlink" title="按分类生成路径"></a>按分类生成路径</h2><p>文章的链接地址默认是按日期生成的，这样当要链接到自己文章时不太方便，可以改为按分类生成</p>
<p>修改网站文件</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">permalink:</span> <span class="string">:category/:title/</span></span><br></pre></td></tr></table></figure>
<h2 id="排序规则"><a href="#排序规则" class="headerlink" title="排序规则"></a>排序规则</h2><p>默认是按发布时间倒序的，这里改成了按更新时间</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">index_generator:</span></span><br><span class="line"><span class="attr">  path:</span> <span class="string">''</span></span><br><span class="line"><span class="attr">  per_page:</span> <span class="number">10</span></span><br><span class="line"><span class="attr">  order_by:</span> <span class="bullet">-updated</span></span><br></pre></td></tr></table></figure>
<h2 id="图片问题"><a href="#图片问题" class="headerlink" title="图片问题"></a>图片问题</h2><p>因为我将图片全放到了E:\blog\source\images目录下，所以在外网访问时图片的路径是这个样子的</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/blog/images/1532877733213.png</span><br></pre></td></tr></table></figure>
<p>为了保证撰写文章时图片也能正常显示所以需要做一些调整</p>
<p>将网站配置源文件目录改为blog</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">source_dir: blog</span><br></pre></td></tr></table></figure>
<p>每次插入图片时将图片复制到E:\blog\blog\images</p>
<p>我用的markdown编辑器是<a href="https://www.typora.io/" target="_blank" rel="noopener">typroa</a><br>需要在头部做一些配置，这样就保证能本地链接的地址和网站地址一致，同时在每次插入图片时自动复制到指定目录</p>
<p>最终每次创建md文件时，都需要这么一个文件头</p>
<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: </span><br><span class="line">date: </span><br><span class="line">categories: []</span><br><span class="line">tags: []</span><br><span class="line">typora-copy-images-to: ../images</span><br><span class="line">typora-root-url:  E:/blog/</span><br><span class="line">---</span><br></pre></td></tr></table></figure>
<p>写了一个文件（blog.py）专门干这事，每次要写博客的时候只要双击这个文件就可以了</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: UTF-8 -*-</span></span><br><span class="line"><span class="keyword">import</span> datetime</span><br><span class="line"><span class="keyword">import</span> subprocess</span><br><span class="line"><span class="keyword">import</span> threading</span><br><span class="line">now = datetime.datetime.now()</span><br><span class="line">fileName= now.strftime(<span class="string">"%Y%m%d%H%M%S"</span>)</span><br><span class="line">now = now.strftime(<span class="string">"%Y-%m-%d %H:%M:%S"</span>)</span><br><span class="line"></span><br><span class="line">head=<span class="string">'''---</span></span><br><span class="line"><span class="string">title: </span></span><br><span class="line"><span class="string">date: &#123;&#125;</span></span><br><span class="line"><span class="string">categories: []</span></span><br><span class="line"><span class="string">tags: []</span></span><br><span class="line"><span class="string">typora-copy-images-to: ../images</span></span><br><span class="line"><span class="string">typora-root-url:  E:/blog</span></span><br><span class="line"><span class="string">---</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&lt;!--more--&gt;</span></span><br><span class="line"><span class="string">'''</span>.format(now)</span><br><span class="line"></span><br><span class="line">fileName=<span class="string">'E:/blog/blog/_posts/'</span>+fileName+<span class="string">'.md'</span></span><br><span class="line">fileHandle = open (fileName, <span class="string">'w'</span> )</span><br><span class="line">fileHandle.write (head)</span><br><span class="line">fileHandle.close()</span><br><span class="line">print(<span class="string">"创建文件:"</span>+fileName)</span><br><span class="line">cmd=<span class="string">"cmd /c D:/Typora/Typora.exe "</span>+fileName</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">action</span><span class="params">()</span>:</span></span><br><span class="line">    subprocess.call(cmd,shell=<span class="keyword">True</span>,stdout=subprocess.PIPE)</span><br><span class="line">t=threading.Thread(target=action)</span><br><span class="line">t.start()</span><br></pre></td></tr></table></figure>
<h1 id="插件"><a href="#插件" class="headerlink" title="插件"></a>插件</h1><h2 id="markdown画图"><a href="#markdown画图" class="headerlink" title="markdown画图"></a>markdown画图</h2><p>原始的hexo是不支持作图的，需要安装插件，目前试了只有流程图能用</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install --save hexo-filter-flowchart</span><br></pre></td></tr></table></figure>
<p>其它类型的图，暂时只能通过截图方式。。。</p>
<h2 id="站内搜索"><a href="#站内搜索" class="headerlink" title="站内搜索"></a>站内搜索</h2><p>我大部分时间拿博客当云笔记用，所以搜索功能必不可少，幸好有插件实现了站内搜索功能</p>
<h3 id="安装插件"><a href="#安装插件" class="headerlink" title="安装插件"></a>安装插件</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-generator-searchdb --save</span><br></pre></td></tr></table></figure>
<h3 id="修改站点文件"><a href="#修改站点文件" class="headerlink" title="修改站点文件"></a>修改站点文件</h3><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">search:</span></span><br><span class="line"><span class="attr">  path:</span> <span class="string">search.xml</span></span><br><span class="line"><span class="attr">  field:</span> <span class="string">post</span></span><br><span class="line"><span class="attr">  format:</span> <span class="string">html</span></span><br><span class="line"><span class="attr">  limit:</span> <span class="number">10000</span></span><br></pre></td></tr></table></figure>
<h3 id="修改主题文件-1"><a href="#修改主题文件-1" class="headerlink" title="修改主题文件"></a>修改主题文件</h3><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">local_search:</span></span><br><span class="line"><span class="attr">  enable:</span> <span class="literal">true</span></span><br></pre></td></tr></table></figure>
<h3 id="最终效果"><a href="#最终效果" class="headerlink" title="最终效果"></a>最终效果</h3><p><img src="/blog/images/1532687467766.png" alt="1532687467766"></p>
<h2 id="阅读次数"><a href="#阅读次数" class="headerlink" title="阅读次数"></a>阅读次数</h2><p>next内部已经集成了leancloud，我们要做的只是开启这个功能</p>
<h3 id="修改主题文件-2"><a href="#修改主题文件-2" class="headerlink" title="修改主题文件"></a>修改主题文件</h3><p>将leancloud_visitors.enable设true，并配置app_id和app_key，这两个值需要到leancloud上获取</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">leancloud_visitors:</span></span><br><span class="line"><span class="attr">  enable:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">  app_id:</span> <span class="string">XXXXXXXXXXX</span></span><br><span class="line"><span class="attr">  app_key:</span> <span class="string">XXXXXXXXXXXXXXX</span></span><br></pre></td></tr></table></figure>
<h3 id="注册并登录leancloud"><a href="#注册并登录leancloud" class="headerlink" title="注册并登录leancloud"></a>注册并登录leancloud</h3><p>略</p>
<h3 id="创建应用"><a href="#创建应用" class="headerlink" title="创建应用"></a>创建应用</h3><p>点击头像–&gt;点击应用按钮–&gt;创建新应用</p>
<p><img src="/blog/images/1532931914832.png" alt="1532931914832"></p>
<p>输入应用名，点击创建</p>
<p><img src="/blog/images/1532932008703.png" alt="1532932008703"></p>
<h3 id="创建Class"><a href="#创建Class" class="headerlink" title="创建Class"></a>创建Class</h3><p>选择刚才创建的应用后，点击云存储–&gt;创建class–&gt;输入class名称–&gt;创建class</p>
<p>这里名称要写<strong>Counter</strong></p>
<p><img src="/blog/images/1532932150226.png" alt="1532932124339"></p>
<h3 id="获取app-id和app-key"><a href="#获取app-id和app-key" class="headerlink" title="获取app_id和app_key"></a>获取app_id和app_key</h3><p>将设置–&gt;应用Key下的App ID和App Key写到上面说的主题文件里面</p>
<p><img src="/blog/images/1532932378669.png" alt="1532932378669"></p>
<h3 id="发布应用"><a href="#发布应用" class="headerlink" title="发布应用"></a>发布应用</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">e:</span><br><span class="line">cd E:\blog\public\blog</span><br><span class="line">hexo g</span><br><span class="line">git add .</span><br><span class="line">git commit -am '新增显示阅读次数功能'</span><br><span class="line">git push</span><br></pre></td></tr></table></figure>
<h3 id="最终效果-1"><a href="#最终效果-1" class="headerlink" title="最终效果"></a>最终效果</h3><p><img src="/blog/images/1532932631263.png" alt="1532932631263"></p>
<p>访问网页后点击Counter可以查看实际存储的数据的值，time就是保存的阅读次数，可以随意修改</p>
<p><img src="/blog/images/1532933159586.png" alt="1532932768632"></p>
<h2 id="评论"><a href="#评论" class="headerlink" title="评论"></a>评论</h2><h1 id="可能遇到问题"><a href="#可能遇到问题" class="headerlink" title="可能遇到问题"></a>可能遇到问题</h1><h2 id="无法删除文件"><a href="#无法删除文件" class="headerlink" title="无法删除文件"></a>无法删除文件</h2><p>某些情况下会发现.md文件已经删除了，但最终还是会生成html，这时候需要清一下缓存。但clean命令会将整个public目录删掉，git信息也没了，所以需要先备份一下，具体命令如下</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">cd E:\blog</span><br><span class="line">ren E:\blog\public public1</span><br><span class="line">hexo clean</span><br><span class="line">ren E:\blog\public1 public</span><br><span class="line">hexo g</span><br></pre></td></tr></table></figure>
<p><img src="/blog/images/1532896295850.png" alt="1532896295850"></p>
<h2 id="404"><a href="#404" class="headerlink" title="404"></a>404</h2><p>代码刚发布立即访问，有可能遇到临时无法访问的情况。如果不是这个原因，确认一下代码是否提交了，</p>
<p>使用TortoiseGit，默认是不提交新增文件的，所以commit前记得点一下All</p>
<p><img src="/blog/images/1532933462735.png" alt="1532933462735"></p>
<h2 id="Template-render-error"><a href="#Template-render-error" class="headerlink" title="Template render error"></a>Template render error</h2><p>生成html页面的时候报错</p>
<p><img src="/blog/images/1532949407329.png" alt="1532949407329"></p>
<p>可能原因是md文件里写了这样的代码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;#xxx&#125;</span><br></pre></td></tr></table></figure>
<p>解决办法，想我这样写在代码块里就好了</p>

      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/hexo/" rel="tag"># hexo</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/code/spring/springMVC/develop/springMVC/" rel="next" title="springMVC组件说明">
                <i class="fa fa-chevron-left"></i> springMVC组件说明
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/数据库/mysql/database/centos7安装mysql/" rel="prev" title="centos7下安装mysql">
                centos7下安装mysql <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/blog/archives">
                
                    <span class="site-state-item-count">54</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/blog/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">25</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/blog/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">45</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          
          

          
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#准备工作"><span class="nav-number">1.</span> <span class="nav-text">准备工作</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#安装hexo"><span class="nav-number">2.</span> <span class="nav-text">安装hexo</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#创建项目"><span class="nav-number">3.</span> <span class="nav-text">创建项目</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#更换主题"><span class="nav-number">4.</span> <span class="nav-text">更换主题</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#基础配置"><span class="nav-number">5.</span> <span class="nav-text">基础配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#标题"><span class="nav-number">5.1.</span> <span class="nav-text">标题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#语言"><span class="nav-number">5.2.</span> <span class="nav-text">语言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#添加分类和标签"><span class="nav-number">5.3.</span> <span class="nav-text">添加分类和标签</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#新建页面"><span class="nav-number">5.3.1.</span> <span class="nav-text">新建页面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改生成页面的内容"><span class="nav-number">5.3.2.</span> <span class="nav-text">修改生成页面的内容</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改主题文件"><span class="nav-number">5.3.3.</span> <span class="nav-text">修改主题文件</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#开始撰写"><span class="nav-number">6.</span> <span class="nav-text">开始撰写</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#头部信息"><span class="nav-number">6.1.</span> <span class="nav-text">头部信息</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#文章主体"><span class="nav-number">6.2.</span> <span class="nav-text">文章主体</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#实际效果"><span class="nav-number">7.</span> <span class="nav-text">实际效果</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#首页"><span class="nav-number">7.1.</span> <span class="nav-text">首页</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#阅读全文"><span class="nav-number">7.2.</span> <span class="nav-text">阅读全文</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#分类"><span class="nav-number">7.3.</span> <span class="nav-text">分类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#标签"><span class="nav-number">7.4.</span> <span class="nav-text">标签</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#发布到网上"><span class="nav-number">8.</span> <span class="nav-text">发布到网上</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#修改项目根路径"><span class="nav-number">8.1.</span> <span class="nav-text">修改项目根路径</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#修改网站文件"><span class="nav-number">8.2.</span> <span class="nav-text">修改网站文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#下载项目到本地"><span class="nav-number">8.3.</span> <span class="nav-text">下载项目到本地</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#修改生成目录"><span class="nav-number">8.4.</span> <span class="nav-text">修改生成目录</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#生成静态页面"><span class="nav-number">8.5.</span> <span class="nav-text">生成静态页面</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#提交到网站"><span class="nav-number">8.6.</span> <span class="nav-text">提交到网站</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#commit"><span class="nav-number">8.6.1.</span> <span class="nav-text">commit</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#push"><span class="nav-number">8.6.2.</span> <span class="nav-text">push</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#总结"><span class="nav-number">9.</span> <span class="nav-text">总结</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#个性化配置"><span class="nav-number">10.</span> <span class="nav-text">个性化配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#按分类生成路径"><span class="nav-number">10.1.</span> <span class="nav-text">按分类生成路径</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#排序规则"><span class="nav-number">10.2.</span> <span class="nav-text">排序规则</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#图片问题"><span class="nav-number">10.3.</span> <span class="nav-text">图片问题</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#插件"><span class="nav-number">11.</span> <span class="nav-text">插件</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#markdown画图"><span class="nav-number">11.1.</span> <span class="nav-text">markdown画图</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#站内搜索"><span class="nav-number">11.2.</span> <span class="nav-text">站内搜索</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装插件"><span class="nav-number">11.2.1.</span> <span class="nav-text">安装插件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改站点文件"><span class="nav-number">11.2.2.</span> <span class="nav-text">修改站点文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改主题文件-1"><span class="nav-number">11.2.3.</span> <span class="nav-text">修改主题文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#最终效果"><span class="nav-number">11.2.4.</span> <span class="nav-text">最终效果</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#阅读次数"><span class="nav-number">11.3.</span> <span class="nav-text">阅读次数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#修改主题文件-2"><span class="nav-number">11.3.1.</span> <span class="nav-text">修改主题文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#注册并登录leancloud"><span class="nav-number">11.3.2.</span> <span class="nav-text">注册并登录leancloud</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#创建应用"><span class="nav-number">11.3.3.</span> <span class="nav-text">创建应用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#创建Class"><span class="nav-number">11.3.4.</span> <span class="nav-text">创建Class</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取app-id和app-key"><span class="nav-number">11.3.5.</span> <span class="nav-text">获取app_id和app_key</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#发布应用"><span class="nav-number">11.3.6.</span> <span class="nav-text">发布应用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#最终效果-1"><span class="nav-number">11.3.7.</span> <span class="nav-text">最终效果</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#评论"><span class="nav-number">11.4.</span> <span class="nav-text">评论</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#可能遇到问题"><span class="nav-number">12.</span> <span class="nav-text">可能遇到问题</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#无法删除文件"><span class="nav-number">12.1.</span> <span class="nav-text">无法删除文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#404"><span class="nav-number">12.2.</span> <span class="nav-text">404</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Template-render-error"><span class="nav-number">12.3.</span> <span class="nav-text">Template render error</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder"></span>

  

  
</div>




  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动 v3.7.1</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://theme-next.org">NexT.Pisces</a> v6.3.0</div>





<span id="busuanzi_container_site_uv">
  &nbsp;<span id="busuanzi_value_site_uv"></span>
</span>

<span>/</span>

<span id="busuanzi_container_site_pv">
    <span id="busuanzi_value_site_pv"></span>
</span>


        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    
	
    

    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=6.3.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=6.3.0"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=6.3.0"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=6.3.0"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=6.3.0"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=6.3.0"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=6.3.0"></script>



  



  










  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("CIBUz5A0KNFv8xbAPO8ncqk6-gzGzoHsz", "YtGifAKqwENTTs9hhQ1GxdAG");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            
            counter.save(null, {
              success: function(counter) {
                
                  var $element = $(document.getElementById(url));
                  $element.find('.leancloud-visitors-count').text(counter.get('time'));
                
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            
              var newcounter = new Counter();
              /* Set ACL */
              var acl = new AV.ACL();
              acl.setPublicReadAccess(true);
              acl.setPublicWriteAccess(true);
              newcounter.setACL(acl);
              /* End Set ACL */
              newcounter.set("title", title);
              newcounter.set("url", url);
              newcounter.set("time", 1);
              newcounter.save(null, {
                success: function(newcounter) {
                  var $element = $(document.getElementById(url));
                  $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
                },
                error: function(newcounter, error) {
                  console.log('Failed to create');
                }
              });
            
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  
  

  

  

  

  

  

</body>
</html>
